package com.salim.leetcode.$9;

/**
 * Created with IntelliJ IDEA.
 * User: clevo
 * Date: 15-9-16
 * Time: 上午11:12
 * To change this template use File | Settings | File Templates.
 */
public class isPalindrome {
    public boolean isPalindrome(int x) {
        if(x==0){
            return true;
        }
        if(x<0){
            return false;
        }
        int count= 0;
        int tempx=x;
        while(tempx>0){
            tempx/=10;
            count++;
        }
        if(count==1){
            return true;
        }
        int indexLeft = count;
        int indexRight = 1;
        while(indexLeft>0){
            if(indexLeft<indexRight){
                break;
            }
            int left =x;
            int right = 1;
            for(int i=0;i<indexLeft-1;i++){
                left/=10;
            }
            indexLeft--;
            for(int i=0;i<indexRight-1;i++){
                right*=10;
            }
            indexRight++;
            if(left%10==(x/right)%10){
                continue;
            }else{
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args){
        isPalindrome temp = new isPalindrome();
/*        System.out.println(temp.isPalindrome(1234554321));
        System.out.println(temp.isPalindrome(0));
        System.out.println(temp.isPalindrome(12));*/
        System.out.println(temp.isPalindrome(Integer.MIN_VALUE));
    }
}
